package com.emenu;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import com.emenu.RightTopFragment.RightAdapter;
import com.emenu.application.StaticObject;
import com.emenu.bean.BusHitDetail;
import com.emenu.bean.Menu;
import com.emenu.bean.StackBean;
import com.emenu.bean.SubMenu;
import com.emenu.common.SaveMenuImg;

import android.app.Activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.FragmentManager;

public class LeftFragment extends Fragment {
	private ImageView image1;
	private TextView name1;
	private TextView pric1;
	private ImageView image2;
	private TextView name2;
	private TextView pric2;
	private ImageView image3;
	private TextView name3;
	private TextView pric3;
	private ImageView image4;
	private TextView name4;
	private TextView pric4;
	private ImageView image5;
	private TextView name5;
	private TextView pric5;
	private ImageView image6;
	private TextView name6;
	private TextView pric6;
	

	private TextView cur;
	private TextView total;
	// private TextView page_path;

	private ImageButton button_left;
	private ImageButton button_allleft;
	private ImageButton button_right;
	private ImageButton button_allright;

	private Button button_choose1;
	private Button button_choose2;
	private Button button_choose3;
	private Button button_choose4;
	private Button button_choose5;
	private Button button_choose6;
	

	int intPageSize = 6;// 页面数
	int intRowCount;// 记录数
	int totalpage;// 总页面
	int currentpage = 1;// 当前页面

	int i = 0;

	StaticObject SO;
	List<SubMenu> sublist;
	List<Menu> menulist;
	List<BusHitDetail> bhdList;
	Menu leftmenu = new Menu();
	SubMenu smenuDtl = new SubMenu();

	Bitmap bm;

	Context cn;
	// RightTopFragment RightFragment;
	FragmentManager fm;

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);

		SO = (StaticObject) getActivity().getApplication();
		menulist = SO.getMenuList();
		sublist = SO.getSubMenuList();
		bhdList = SO.getBusHitDetailList();

		cn = this.getActivity();

		StackBean sb = new StackBean();
		sb.setName(menulist.get(0).getName());
		SO.getStackList().clear();
		SO.getStackList().add(sb);

		fm = ((FragmentMAin) cn).getSupportFragmentManager();
		
		// ((FragmentMAin) cn).button_back.setVisibility(View.INVISIBLE);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View v = inflater.inflate(R.layout.left, container, false);

		findViewsById(v);
		setListener();
		showImage(menulist.get(0), currentpage);
		return v;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {

		super.onActivityCreated(savedInstanceState);
		((FragmentMAin) cn).showpath();

	}

	/** 视图 样式 */
	private void findViewsById(View v) {
		image1 = (ImageView) v.findViewById((R.id.menuId1));
		name1 = (TextView) v.findViewById((R.id.txtname1));
		pric1 = (TextView) v.findViewById((R.id.txtprice1));
		image2 = (ImageView) v.findViewById((R.id.menuId2));
		name2 = (TextView) v.findViewById((R.id.txtname2));
		pric2 = (TextView) v.findViewById((R.id.txtprice2));
		image3 = (ImageView) v.findViewById((R.id.menuId3));
		name3 = (TextView) v.findViewById((R.id.txtname3));
		pric3 = (TextView) v.findViewById((R.id.txtprice3));
		image4 = (ImageView) v.findViewById((R.id.menuId4));
		name4 = (TextView) v.findViewById((R.id.txtname4));
		pric4 = (TextView) v.findViewById((R.id.txtprice4));
		image5 = (ImageView) v.findViewById((R.id.menuId5));
		name5 = (TextView) v.findViewById((R.id.txtname5));
		pric5 = (TextView) v.findViewById((R.id.txtprice5));
		image6 = (ImageView) v.findViewById((R.id.menuId6));
		name6 = (TextView) v.findViewById((R.id.txtname6));
		pric6 = (TextView) v.findViewById((R.id.txtprice6));
		

		cur = (TextView) v.findViewById((R.id.page_cur));
		total = (TextView) v.findViewById((R.id.page_total));

		button_left = (ImageButton) v.findViewById((R.id.page_left));
		button_allleft = (ImageButton) v.findViewById((R.id.page_topleft));
		button_right = (ImageButton) v.findViewById((R.id.page_right));
		button_allright = (ImageButton) v.findViewById((R.id.page_topright));

		button_choose1 = (Button) v.findViewById((R.id.choose1));
		button_choose2 = (Button) v.findViewById((R.id.choose2));
		button_choose3 = (Button) v.findViewById((R.id.choose3));
		button_choose4 = (Button) v.findViewById((R.id.choose4));
		button_choose5 = (Button) v.findViewById((R.id.choose5));
		button_choose6 = (Button) v.findViewById((R.id.choose6));
		

	}

	/** 设置监听器 */
	private void setListener() {
		button_left.setOnClickListener(leftListener);
		button_allleft.setOnClickListener(allLeftListener);
		button_right.setOnClickListener(rightListener);
		button_allright.setOnClickListener(allRightListener);
	}

	private OnClickListener leftListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			if (null != bm && !bm.isRecycled()) {
				bm.recycle();
			}

			currentpage--;
			if (currentpage > 0) {
				if (null == smenuDtl.getName() || "".equals(smenuDtl.getName())) {
					showImage(leftmenu, currentpage);
				} else {
					showImageDtl(smenuDtl, currentpage);
				}
			}

		}
	};

	private OnClickListener allLeftListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			if (null != bm && !bm.isRecycled()) {
				bm.recycle();
			}

			currentpage = 1;
			if (currentpage > 0) {
				if (null == smenuDtl.getName() || "".equals(smenuDtl.getName())) {
					showImage(leftmenu, currentpage);
				} else {
					showImageDtl(smenuDtl, currentpage);
				}
			}
		}
	};

	private OnClickListener rightListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			if (null != bm && !bm.isRecycled()) {
				bm.recycle();
			}

			currentpage++;

			if (currentpage > 0) {
				if (null == smenuDtl.getName() || "".equals(smenuDtl.getName())) {
					showImage(leftmenu, currentpage);
				} else {
					showImageDtl(smenuDtl, currentpage);
				}
			}
		}
	};

	private OnClickListener allRightListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			if (null != bm && !bm.isRecycled()) {
				bm.recycle();
			}

			currentpage = totalpage;
			if (currentpage > 0) {
				if (null == smenuDtl.getName() || "".equals(smenuDtl.getName())) {
					showImage(leftmenu, currentpage);
				} else {
					showImageDtl(smenuDtl, currentpage);
				}
			}
		}
	};

	/**
	 * 显示大类下的图片
	 * 
	 * @param menu
	 */
	public void showImage(Menu menu, int currentpage) {

		String SDPATH = Environment.getExternalStorageDirectory()
				+ File.separator + "Picture" + File.separator;

		leftmenu = menu;

		List<SubMenu> slist = new ArrayList<SubMenu>();

		for (SubMenu smenu : sublist) {
			if (smenu.getMenu_code().equals(menu.getCode())) {

				slist.add(smenu);
			}

		}
		if (slist.size() < 1) {
			return;
		}

		intRowCount = slist.size();
		totalpage = (intRowCount + intPageSize - 1) / intPageSize;
		if (currentpage > totalpage) {
			currentpage = totalpage;
		}
		if (currentpage < 1) {
			currentpage = 1;
		}
		// 当前页在最大页前
		int j;
		if (currentpage < totalpage) {
			for (int i = (currentpage - 1) * intPageSize; i <= (currentpage - 1) * intPageSize + 5; i++) {
				j = 0;
				SubMenu menuD = slist.get(i);

				String fileName = SDPATH
						+ SaveMenuImg.getpath(menuD.getPicpath())
						+ menuD.getName() + ".jpg";

				if (currentpage == 1) {
					j = i;
				} else {
					j = i % intPageSize;
				}
				setview(fileName, j, menuD);

			}

		} else {// 当前页等于最大页
			for (int i = (currentpage - 1) * intPageSize; i < slist.size(); i++) {
				j = 0;
				SubMenu menuD = slist.get(i);
				String fileName = SDPATH
						+ SaveMenuImg.getpath(menuD.getPicpath())
						+ menuD.getName() + ".jpg";
				if (currentpage == 1) {
					j = i;
				} else {
					j = i % intPageSize;
				}
				setview(fileName, j, menuD);

			}
		}
		cur.setText("当前：" + currentpage + " 页");
		total.setText("共：" + totalpage + " 页");
	}

	/**
	 * 点击submenu，显示submenu下级类别的图片
	 * 
	 * @param SubMenu
	 */
	public void showImageDtl(SubMenu smenu, int currentpage) {
		if (null != bm && !bm.isRecycled()) {
			bm.recycle();
		}
		String SDPATH = Environment.getExternalStorageDirectory()
				+ File.separator + "Picture" + File.separator;
		// if (this.leftmenu.getName().length() > 0) {
		smenuDtl = smenu;
		// }

		List<SubMenu> slist = new ArrayList<SubMenu>();

		for (SubMenu su : sublist) {
			if (smenu.getCode().equals(su.getUpcode())) {

				slist.add(su);
			}

		}
		if (slist.size() < 1) {
			return;
		}

		intRowCount = slist.size();
		totalpage = (intRowCount + intPageSize - 1) / intPageSize;
		if (currentpage > totalpage) {
			currentpage = totalpage;
		}
		if (currentpage < 1) {
			currentpage = 1;
		}
		// 当前页在最大页前
		int j;
		if (currentpage < totalpage) {
			for (int i = (currentpage - 1) * intPageSize; i <= (currentpage - 1) * intPageSize + 5; i++) {
				j = 0;
				SubMenu suD = slist.get(i);

				if (currentpage == 1) {
					j = i;
				} else {
					j = i % intPageSize;
				}

				String fileName = SDPATH
						+ SaveMenuImg.getpath(suD.getPicpath()) + suD.getName()
						+ ".jpg";

				setview(fileName, j, suD);

			}

		} else {// 当前页等于最大页
			for (int i = (currentpage - 1) * intPageSize; i < slist.size(); i++) {
				j = 0;
				SubMenu suD = slist.get(i);
				String fileName = SDPATH
						+ SaveMenuImg.getpath(suD.getPicpath()) + suD.getName()
						+ ".jpg";
				if (currentpage == 1) {
					j = i;
				} else {
					j = i % intPageSize;
				}
				setview(fileName, j, suD);

			}
		}
		cur.setText("当前：" + currentpage + " 页");
		total.setText("共：" + totalpage + " 页");
	}

	private void setview(String fileName, int index, final SubMenu smenu) {

		BitmapFactory.Options options = new BitmapFactory.Options();
		// 图片宽高苏缩小1/2
		options.inSampleSize = 2;

		bm = BitmapFactory.decodeFile(fileName, options);
		if (bm == null) {
			bm = BitmapFactory.decodeStream(getResources().openRawResource(
					R.drawable.imgdefault));
		}

		switch (index) {
		case 0:

			image1.setImageBitmap(bm);
			image1.setOnClickListener(new OnClickListener() {
				public void onClick(View v) {

					// 设置控件不可用，防止跳转到下一fragment,当前fragment被遮挡但事件仍可用
					//unAbleView();
					onPause();

					if (smenu.getIs_Node() == 1 && smenu.getIs_Serise() == 0) {

						FragmentTransaction ft = getFragmentManager()
								.beginTransaction();

						FragmentHit hit = new FragmentHit();

						Bundle args = new Bundle();
						args.putString("code", smenu.getCode());
						args.putDouble("amount", 1);
						hit.setArguments(args);

						ft.replace(R.id.left, hit);
						ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
						ft.addToBackStack(null);

						ft.commit();
					} else if (smenu.getIs_Node() == 1
							&& smenu.getIs_Serise() == 1) {
						FragmentTransaction ft = getFragmentManager()
								.beginTransaction();

						FragmentSetMeal SetMeal = new FragmentSetMeal();
						Bundle args = new Bundle();
						args.putString("code", smenu.getCode());
						args.putDouble("amount", 1);
						SetMeal.setArguments(args);

						ft.replace(R.id.left, SetMeal);
						ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
						ft.addToBackStack(null);

						ft.commit();

					} else {
						currentpage = 1;
						showImageDtl(smenu, currentpage);
					}

				}

			});

			name1.setText(smenu.getName());
			pric1.setText(String.valueOf(smenu.getPrice()) + "/"
					+ smenu.getTag_name());

			button_choose1.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					int itemp = 0;
					for (BusHitDetail bhd : bhdList) {

						if (bhd.getMenucode().equals(smenu.getCode())) {
							bhd.setAmount(bhd.getAmount() + 1);
							itemp = 1;
							break;
						}
					}

					if (itemp != 1) {
						chooseMenu(smenu);
					}

					for (Menu mu : SO.getMenuList()) {

						if (mu.getCode().equals(smenu.getMenu_code())) {
							mu.setCount(mu.getCount() + 1);
						}
						if (mu.getC1() == smenu.getRljtype()) {
							mu.setCount(mu.getCount() + 1);
						}
						if(mu.getC1()==-1){
							mu.setCount(mu.getCount() + 1);
						}
					}
					((FragmentMAin) cn).refreshRight();
				}
			});

		case 1:
			image2.setImageBitmap(bm);
			image2.setOnClickListener(new OnClickListener() {
				public void onClick(View v) {
					// 设置控件不可用，防止跳转到下一fragment,当前fragment被遮挡但事件仍可用
					onPause();
					if (smenu.getIs_Node() == 1) {
						FragmentTransaction ft = getFragmentManager()
								.beginTransaction();

						FragmentHit hit = new FragmentHit();
						Bundle args = new Bundle();
						args.putString("code", smenu.getCode());
						args.putDouble("amount", 1);
						hit.setArguments(args);

						ft.replace(R.id.left, hit);
						ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
						ft.addToBackStack(null);

						ft.commit();
					} else if (smenu.getIs_Node() == 1
							&& smenu.getIs_Serise() == 1) {
						FragmentTransaction ft = getFragmentManager()
								.beginTransaction();

						FragmentSetMeal SetMeal = new FragmentSetMeal();
						Bundle args = new Bundle();
						args.putString("code", smenu.getCode());
						args.putDouble("amount", 1);
						SetMeal.setArguments(args);

						ft.replace(R.id.left, SetMeal);
						ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
						ft.addToBackStack(null);

						ft.commit();

					} else {
						currentpage = 1;
						showImageDtl(smenu, currentpage);
					}

				}
			});
			name2.setText(smenu.getName());
			pric2.setText(String.valueOf(smenu.getPrice()) + "/"
					+ smenu.getTag_name());
			button_choose2.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					int itemp = 0;
					for (BusHitDetail bhd : bhdList) {
						if (bhd.getMenucode().equals(smenu.getCode())) {
							bhd.setAmount(bhd.getAmount() + 1);
							itemp = 1;
							break;
						}
					}

					if (itemp != 1) {
						chooseMenu(smenu);
					}

					for (Menu mu : SO.getMenuList()) {
						if (mu.getCode().equals(smenu.getMenu_code())) {
							mu.setCount(mu.getCount() + 1);
						}
						if (mu.getC1() == smenu.getRljtype()) {
							mu.setCount(mu.getCount() + 1);
						}
						if(mu.getC1()==-1){
							mu.setCount(mu.getCount() + 1);
						}
					}
					((FragmentMAin) cn).refreshRight();
				}
			});
		case 2:
			image3.setImageBitmap(bm);
			image3.setOnClickListener(new OnClickListener() {
				public void onClick(View v) {
					// 设置控件不可用，防止跳转到下一fragment,当前fragment被遮挡但事件仍可用
					onPause();
					if (smenu.getIs_Node() == 1 && smenu.getIs_Serise() == 0) {
						FragmentTransaction ft = getFragmentManager()
								.beginTransaction();

						FragmentHit hit = new FragmentHit();
						Bundle args = new Bundle();
						args.putString("code", smenu.getCode());
						args.putDouble("amount", 1);
						hit.setArguments(args);

						ft.replace(R.id.left, hit);
						ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
						ft.addToBackStack(null);

						ft.commit();
					} else if (smenu.getIs_Node() == 1
							&& smenu.getIs_Serise() == 1) {
						FragmentTransaction ft = getFragmentManager()
								.beginTransaction();

						FragmentSetMeal SetMeal = new FragmentSetMeal();
						Bundle args = new Bundle();
						args.putString("code", smenu.getCode());
						args.putDouble("amount", 1);
						SetMeal.setArguments(args);

						ft.replace(R.id.left, SetMeal);
						ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
						ft.addToBackStack(null);

						ft.commit();

					} else {
						currentpage = 1;
						showImageDtl(smenu, currentpage);

					}

				}
			});
			name3.setText(smenu.getName());
			pric3.setText(String.valueOf(smenu.getPrice()) + "/"
					+ smenu.getTag_name());
			button_choose3.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					int itemp = 0;
					for (BusHitDetail bhd : bhdList) {
						if (bhd.getMenucode().equals(smenu.getCode())) {
							bhd.setAmount(bhd.getAmount() + 1);
							itemp = 1;
							break;
						}
					}

					if (itemp != 1) {
						chooseMenu(smenu);
					}

					for (Menu mu : SO.getMenuList()) {
						if (mu.getCode().equals(smenu.getMenu_code())) {
							mu.setCount(mu.getCount() + 1);
						}
						if (mu.getC1() == smenu.getRljtype()) {
							mu.setCount(mu.getCount() + 1);
						}
						if(mu.getC1()==-1){
							mu.setCount(mu.getCount() + 1);
						}
					}
					((FragmentMAin) cn).refreshRight();
				}
			});
		case 3:
			image4.setImageBitmap(bm);
			image4.setOnClickListener(new OnClickListener() {
				public void onClick(View v) {
					// 设置控件不可用，防止跳转到下一fragment,当前fragment被遮挡但事件仍可用
					onPause();
					if (smenu.getIs_Node() == 1 && smenu.getIs_Serise() == 0) {
						FragmentTransaction ft = getFragmentManager()
								.beginTransaction();

						FragmentHit hit = new FragmentHit();
						Bundle args = new Bundle();
						args.putString("code", smenu.getCode());
						args.putDouble("amount", 1);
						hit.setArguments(args);

						ft.replace(R.id.left, hit);
						ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
						ft.addToBackStack(null);

						ft.commit();
					} else if (smenu.getIs_Node() == 1
							&& smenu.getIs_Serise() == 1) {
						FragmentTransaction ft = getFragmentManager()
								.beginTransaction();

						FragmentSetMeal SetMeal = new FragmentSetMeal();
						Bundle args = new Bundle();
						args.putString("code", smenu.getCode());
						args.putDouble("amount", 1);
						SetMeal.setArguments(args);

						ft.replace(R.id.left, SetMeal);
						ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
						ft.addToBackStack(null);

						ft.commit();

					} else {
						currentpage = 1;
						showImageDtl(smenu, currentpage);

					}

				}
			});
			name4.setText(smenu.getName());
			pric4.setText(String.valueOf(smenu.getPrice()) + "/"
					+ smenu.getTag_name());
			button_choose4.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					int itemp = 0;
					for (BusHitDetail bhd : bhdList) {
						if (bhd.getMenucode().equals(smenu.getCode())) {
							bhd.setAmount(bhd.getAmount() + 1);
							itemp = 1;
							break;
						}
					}

					if (itemp != 1) {
						chooseMenu(smenu);
					}

					for (Menu mu : SO.getMenuList()) {
						if (mu.getCode().equals(smenu.getMenu_code())) {
							mu.setCount(mu.getCount() + 1);
						}
						if (mu.getC1() == smenu.getRljtype()) {
							mu.setCount(mu.getCount() + 1);
						}
						if(mu.getC1()==-1){
							mu.setCount(mu.getCount() + 1);
						}
					}
					((FragmentMAin) cn).refreshRight();
				}
			});
		case 4:
			image5.setImageBitmap(bm);
			image5.setOnClickListener(new OnClickListener() {
				public void onClick(View v) {
					// 设置控件不可用，防止跳转到下一fragment,当前fragment被遮挡但事件仍可用
					onPause();
					if (smenu.getIs_Node() == 1 && smenu.getIs_Serise() == 0) {
						FragmentTransaction ft = getFragmentManager()
								.beginTransaction();

						FragmentHit hit = new FragmentHit();
						Bundle args = new Bundle();
						args.putString("code", smenu.getCode());
						args.putDouble("amount", 1);
						hit.setArguments(args);

						ft.replace(R.id.left, hit);
						ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
						ft.addToBackStack(null);

						ft.commit();
					} else if (smenu.getIs_Node() == 1
							&& smenu.getIs_Serise() == 1) {
						FragmentTransaction ft = getFragmentManager()
								.beginTransaction();

						FragmentSetMeal SetMeal = new FragmentSetMeal();
						Bundle args = new Bundle();
						args.putString("code", smenu.getCode());
						args.putDouble("amount", 1);
						SetMeal.setArguments(args);

						ft.replace(R.id.left, SetMeal);
						ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
						ft.addToBackStack(null);

						ft.commit();

					} else {
						currentpage = 1;
						showImageDtl(smenu, currentpage);

					}

				}
			});
			name5.setText(smenu.getName());
			pric5.setText(String.valueOf(smenu.getPrice()) + "/"
					+ smenu.getTag_name());
			button_choose5.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					int itemp = 0;
					for (BusHitDetail bhd : bhdList) {
						if (bhd.getMenucode().equals(smenu.getCode())) {
							bhd.setAmount(bhd.getAmount() + 1);
							itemp = 1;
							break;
						}
					}

					if (itemp != 1) {
						chooseMenu(smenu);
					}

					for (Menu mu : SO.getMenuList()) {
						if (mu.getCode().equals(smenu.getMenu_code())) {
							mu.setCount(mu.getCount() + 1);
						}
						if (mu.getC1() == smenu.getRljtype()) {
							mu.setCount(mu.getCount() + 1);
						}
						if(mu.getC1()==-1){
							mu.setCount(mu.getCount() + 1);
						}
					}
					((FragmentMAin) cn).refreshRight();
				}
			});
		case 5:
			image6.setImageBitmap(bm);
			image6.setOnClickListener(new OnClickListener() {
				public void onClick(View v) {
					// 设置控件不可用，防止跳转到下一fragment,当前fragment被遮挡但事件仍可用
					onPause();
					if (smenu.getIs_Node() == 1 && smenu.getIs_Serise() == 0) {
						FragmentTransaction ft = getFragmentManager()
								.beginTransaction();

						FragmentHit hit = new FragmentHit();
						Bundle args = new Bundle();
						args.putString("code", smenu.getCode());
						args.putDouble("amount", 1);
						hit.setArguments(args);

						ft.replace(R.id.left, hit);
						ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
						ft.addToBackStack(null);

						ft.commit();
					} else if (smenu.getIs_Node() == 1
							&& smenu.getIs_Serise() == 1) {
						FragmentTransaction ft = getFragmentManager()
								.beginTransaction();

						FragmentSetMeal SetMeal = new FragmentSetMeal();
						Bundle args = new Bundle();
						args.putString("code", smenu.getCode());
						args.putDouble("amount", 1);
						SetMeal.setArguments(args);

						ft.replace(R.id.left, SetMeal);
						ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
						ft.addToBackStack(null);

						ft.commit();

					} else {
						currentpage = 1;
						showImageDtl(smenu, currentpage);

					}

				}
			});
			name6.setText(smenu.getName());
			pric6.setText(String.valueOf(smenu.getPrice()) + "/"
					+ smenu.getTag_name());
			button_choose6.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					int itemp = 0;
					for (BusHitDetail bhd : bhdList) {
						if (bhd.getMenucode().equals(smenu.getCode())) {
							bhd.setAmount(bhd.getAmount() + 1);
							itemp = 1;
							break;
						}
					}

					if (itemp != 1) {
						chooseMenu(smenu);
					}

					for (Menu mu : SO.getMenuList()) {
						if (mu.getCode().equals(smenu.getMenu_code())) {
							mu.setCount(mu.getCount() + 1);
						}
						if (mu.getC1() == smenu.getRljtype()) {
							mu.setCount(mu.getCount() + 1);
						}
						if(mu.getC1()==-1){
							mu.setCount(mu.getCount() + 1);
						}
					}
					((FragmentMAin) cn).refreshRight();
				}
			});
		 
		}

	}

	// 点击选择后，选择菜品添加到全局变量
	private void chooseMenu(SubMenu su) {
		BusHitDetail bhd = new BusHitDetail();
		// 大类code
		bhd.setBig_Menu_code(su.getMenu_code());
		bhd.setID(-1);
		bhd.setHit_code("-1");
		bhd.setMenucode(su.getCode());
		bhd.setMenuname(su.getName());
		bhd.setPrice(su.getPrice());
		bhd.setAmount(1);
		bhd.setTag_code(su.getTag_code());
		bhd.setTag_name(su.getTag_name());
		bhd.setAmount_sum(Math.round(su.getPrice()));
		bhd.setMenu_type("-1");
		bhd.setRljtype(su.getRljtype());
		bhd.setCalledSingle(0);
		bhd.setRemark("");
		bhd.setUpload(0);
		bhd.setC1("");
		bhd.setC2("");
		bhd.setC3("");
		bhdList.add(bhd);
		SO.setBusHitDetailList(bhdList);

	}

	/***
	 * @Override public void onDestroy() { super.onDestroy(); // 释放图片内存 if
	 *           (!bm.isRecycled()) { bm.recycle(); } }
	 ***/

	private void unAbleView() {
		image1.setClickable(false);
		image2.setClickable(false);
		image3.setClickable(false);
		image4.setClickable(false);
		image5.setClickable(false);
		image6.setClickable(false);
		
		button_left.setClickable(false);
		button_allleft.setClickable(false);
		button_right.setClickable(false);
		button_allright.setClickable(false);

		button_choose1.setClickable(false);
		button_choose2.setClickable(false);
		button_choose3.setClickable(false);
		button_choose4.setClickable(false);
		button_choose5.setClickable(false);
		button_choose6.setClickable(false);
		
	}

	private void enAbleView() {
		image1.setClickable(true);
		image2.setClickable(true);
		image3.setClickable(true);
		image4.setClickable(true);
		image5.setClickable(true);
		image6.setClickable(true);
		
		button_left.setClickable(true);
		button_allleft.setClickable(true);
		button_right.setClickable(true);
		button_allright.setClickable(true);

		button_choose1.setClickable(true);
		button_choose2.setClickable(true);
		button_choose3.setClickable(true);
		button_choose4.setClickable(true);
		button_choose5.setClickable(true);
		button_choose6.setClickable(true);
		
	}

	@Override
	public void onResume() {
		super.onResume();
		// 恢复控件可用
		enAbleView();
	}

	@Override
	public void onPause() {
		super.onPause();
		unAbleView();
	}

}
